#define _CRT_SECURE_NO_WARNINGS
#include <iostream>

using namespace std;

const int N = 1e6 + 10;
long long n, m;
long long x[N];
long long y[N];


int main()
{
    cin >> n >> m;
    long long arr[n][m];
    for (int i = 0;i < n; i++)
        for (int j = 0; j < m; j++)
        {
            cin >> arr[i][j];
            x[i] += arr[i][j];
            y[j] += arr[i][j];
        }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            arr[i][j] = x[i] + y[j] - arr[i][j];
            cout << arr[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}